public class Test {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        int ret = find(arr, 1);
        if (ret >= 0) {
            System.out.println("找到了：" + ret);
        } else {
            System.out.println("没找到！");
        }
    }

    public static int find(int[] arr,int n){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int c=(left+right)/2;
            if(n==arr[c]){
                return c;
            }else if(n>arr[c]){
                left=c+1;
            }else{
                right=c-1;
            }
        }
        return -1;
    }
}
